// import * as Cesium from 'cesium'
    /**
     * A single tile in a {@link CustomTreePrimitive},change from QuadtreeTile.
     *
     * @alias GlobeSpaceTile
     * @constructor
     * @private
     *
     * @param {Number} options.level The level of the tile in the customtree.
     * @param {Number} options.x The X coordinate of the tile in the customtree.  0 is the westernmost tile.
     * @param {Number} options.y The Y coordinate of the tile in the customtree.  0 is the northernmost tile.
     * @param {TilingScheme} options.tilingScheme The tiling scheme in which this tile exists.
     * @param {GlobeSpaceTile} [options.parent] This tile's parent, or undefined if this is a root tile.
     */
    function GlobeSpaceTile(options) {
        //>>includeStart('debug', pragmas.debug);
        if (!Cesium.defined(options)) {
            throw new Cesium.DeveloperError('options is required.');
        }
        if (!Cesium.defined(options.x)) {
            throw new Cesium.DeveloperError('options.x is required.');
        } else if (!Cesium.defined(options.y)) {
            throw new Cesium.DeveloperError('options.y is required.');
        } else if (options.x < 0 || options.y < 0) {
            throw new Cesium.DeveloperError('options.x and options.y must be greater than or equal to zero.');
        }
        if (!Cesium.defined(options.level)) {
            throw new Cesium.DeveloperError('options.level is required and must be greater than or equal to zero.');
        }
        // if (!Cesium.defined(options.tilingScheme)) {
        //     throw new Cesium.DeveloperError('options.tilingScheme is required.');
        // }
        //>>includeEnd('debug');

        this._tilingScheme = options.tilingScheme;
        this._x = options.x;
        this._y = options.y;
        this._level = options.level;
        this.tileRect=undefined;
        this.realRect=undefined;
        
        this._parent = options.parent;
       // this._rectangle = this._tilingScheme.tileXYToRectangle(this._x, this._y, this._level);

        // if(!Cesium.defined(this._parent)){
        //     this._parent=this.parent;
        // }
        this._children=undefined;
        
        //瓦片编码
        this._codeStr=undefined;
        //瓦片所属地球区域NE NW SE SW,用于编码
        this._region=undefined;

        // TileReplacementQueue gets/sets these private properties.
        this.replacementPrevious = undefined;
        this.replacementNext = undefined;

        // The distance from the camera to this tile, updated when the tile is selected
        // for rendering.  We can get rid of this if we have a better way to sort by
        // distance - for example, by using the natural ordering of a quadtree.
        // QuadtreePrimitive gets/sets this private property.
        this._distance = 0.0;
        this._loadPriority = 0.0;

        this._customData = [];
        this._frameUpdated = undefined;
        this._lastSelectionResult = Cesium.TileSelectionResult.NONE;
        this._lastSelectionResultFrame = undefined;
        this._loadedCallbacks = {};

        /**
         * Gets or sets the current state of the tile in the tile load pipeline.
         * @type {Cesium.QuadtreeTileLoadState}
         * @default {@link Cesium.QuadtreeTileLoadState.START}
         */
        this.state = Cesium.QuadtreeTileLoadState.START;

        /**
         * Gets or sets a value indicating whether or not the tile is currently renderable.
         * @type {Boolean}
         * @default false
         */
        this.renderable = false;

        /**
         * Gets or set a value indicating whether or not the tile was entirely upsampled from its
         * parent tile.  If all four children of a parent tile were upsampled from the parent,
         * we will render the parent instead of the children even if the LOD indicates that
         * the children would be preferable.
         * @type {Boolean}
         * @default false
         */
        this.upsampledFromParent = false;

        /**
         * Gets or sets the additional data associated with this tile.  The exact content is specific to the
         * {@link QuadtreeTileProvider}.
         * @type {Object}
         * @default undefined
         */
        this.data = undefined;
    }

    /**
     * Creates a rectangular set of tiles for level of detail zero, the coarsest, least detailed level.
     *
     * @memberof GlobeSpaceTile
     *
     * @param {TilingScheme} tilingScheme The tiling scheme for which the tiles are to be created.
     * @returns {GlobeSpaceTile[]} An array containing the tiles at level of detail zero, starting with the
     * tile in the northwest corner and followed by the tile (if any) to its east.
     */
    GlobeSpaceTile.createLevelZeroTiles = function(tilingScheme) {
 
 
                var tile = new GlobeSpaceTile({
                    
                    x : 0,
                    y : 0,
                    level : 0,
                    tilingScheme:tilingScheme
                });

        tile.tileRect=DMSRectangle.constructWithDegree(-256,-256,256,256);
        tile.realRect=tile.tileRect.clampToEarth();
               
       var result=[];
       result.push(tile);

        return result;
    };
 

    GlobeSpaceTile.prototype._updateCustomData = function(frameNumber, added, removed) {
        var customData = this.customData;

        var i;
        var data;
        var rectangle;

        if (Cesium.defined(added) && Cesium.defined(removed)) {
            customData = customData.filter(function(value) {
                return removed.indexOf(value) === -1;
            });
            this._customData = customData;

            rectangle = this._rectangle;
            for (i = 0; i < added.length; ++i) {
                data = added[i];
                if (Cesium.Rectangle.contains(rectangle, data.positionCartographic)) {
                    customData.push(data);
                }
            }

            this._frameUpdated = frameNumber;
        } else {
            // interior or leaf tile, update from parent
            var parent = this._parent;
            if (Cesium.defined(parent) && this._frameUpdated !== parent._frameUpdated) {
                customData.length = 0;

                rectangle = this._rectangle;
                var parentCustomData = parent.customData;
                for (i = 0; i < parentCustomData.length; ++i) {
                    data = parentCustomData[i];
                    if (Cesium.Rectangle.contains(rectangle, data.positionCartographic)) {
                        customData.push(data);
                    }
                }

                this._frameUpdated = parent._frameUpdated;
            }
        }
    };

    Object.defineProperties(GlobeSpaceTile.prototype, {
      

        /**
         * Gets the tile X coordinate.
         * @memberof GlobeSpaceTile.prototype
         * @type {Number}
         */
        x : {
            get : function() {
                return this._x;
            }
        },

        /**
         * Gets the tile Y coordinate.
         * @memberof GlobeSpaceTile.prototype
         * @type {Number}
         */
        y : {
            get : function() {
                return this._y;
            }
        },

        /**
         * Gets the level-of-detail, where zero is the coarsest, least-detailed.
         * @memberof GlobeSpaceTile.prototype
         * @type {Number}
         */
        level : {
            get : function() {
                return this._level;
            }
        },

        codeStr:{
            get:function(){

                if(!Cesium.defined(this._codeStr)){
                    var x=DMSValue.Add(this.realRect.west,this.realRect.east);
                    x=DMSValue.divide(x,2);
                    var y=DMSValue.Add(this.realRect.north,this.realRect.south);
                    y=DMSValue.divide(y,2);

                    var lonCode=DMSValue.codeDmsValue(x);
                    var latCode=DMSValue.codeDmsValue(y);
                    var motonCode=DMSValue.motonCross(latCode.value,lonCode.value,this.level);
                    if(lonCode.sign>0 && latCode.sign>0){
                        motonCode="G0"+motonCode;
                    }
                    else if(lonCode.sign<0 && latCode.sign>0){
                        motonCode="G1"+motonCode;
                    }
                    else if(lonCode.sign<0 && latCode.sign<0){
                        motonCode="G3"+motonCode;
                    }
                    else{
                        motonCode="G2"+motonCode;
                    }
                    this._codeStr=motonCode;
                }
                return this._codeStr;
            }
        },

        /**
         * Gets the parent tile of this tile.
         * @memberof GlobeSpaceTile.prototype
         * @type {GlobeSpaceTile}
         */
        // parent : {
        //     get : function() {
        //         return this._parent;
        //     }
        // },
        parent:{
            get:function(){
                // var carte=this._tilingScheme.Parent(this._x,this._y,this._level);
                // if(!Cesium.defined(carte)){
                //     return undefined;
                // }
                // var tile=new GlobeSpaceTile({
                //     x:carte.x,
                //     y:carte.y,
                //     level:this._level-1,
                //     tilingScheme:this._tilingScheme
                // });
                // return tile;
                return this._parent;
            }
        },

        /**
         * Gets the cartographic rectangle of the tile, with north, south, east and
         * west properties in radians.
         * @memberof GlobeSpaceTile.prototype
         * @type {Cesium.Rectangle}
         */
        // rectangle : {
        //     get : function() {
        //         return this._rectangle;
        //     }
        // },

        /**
         * An array of tiles that is at the next level of the tile tree.
         * 
         * @memberof GlobeSpaceTile.prototype
         * @type {GlobeSpaceTile[]}
         */
        children : {
            get : function() {
                if(!Cesium.defined(this._children)){
                    var result=[];
                   
                    var x=this.x;
                    var y=this.y;
                    var level=this.level;

                    
  
                    if(level>=0 && level<=8){
                        var parentWest=this.tileRect.west.degree;
                        var parentNorth=this.tileRect.north.degree;
                        var gD=512;
                        var deltaD=gD/(2<<level);
                        for(var row=0;row<2;row++){
                            for(var col=0;col<2;col++){
                                var childTile=new GlobeSpaceTile({
                                    x:2*x+col,
                                    y:2*y+row,
                                    level:level+1,
                                    tilingScheme:this._tilingScheme
                                });
                                var curWest=parentWest+col*deltaD;
                                var curEast=curWest+deltaD;
                                var curNorth=parentNorth-row*deltaD;
                                var curSouth=curNorth-deltaD;

                                childTile.tileRect=DMSRectangle.constructWithDegree(curWest,curSouth,curEast,curNorth);
                                childTile.realRect=childTile.tileRect.clampToEarth();
                                childTile._parent=this;
                                if(Cesium.defined(childTile.realRect))
                                    result.push(childTile);
        
                            }
                        }
                     

                    }
                    else if(level>=9 && level<=14){
                        //变换为第一象限
                        if(!Cesium.defined(this.centerSign)){
                            this.centerSign=this.tileRect.sign();
                        }
                        this.tileRect.changeSign(this.centerSign);
                     
                        var gD=64;
                        if(level==9 && this.tileRect.east.minute==0){
                            this.tileRect.east.degree-=1;
                            this.tileRect.north.degree-=1;
                            this.tileRect.east.minute+=gD;
                            this.tileRect.north.minute+=gD;

                            this.bClamped=true;
                        }

                        var parentWest=this.tileRect.west.minute;
                        var parentNorth=this.tileRect.north.minute;

                        var deltaD=gD/(2<<(level-9));
                        for(var row=0;row<2;row++){
                            for(var col=0;col<2;col++){
                                var childTile=new GlobeSpaceTile({
                                    x:2*x+col,
                                    y:2*y+row,
                                    level:level+1,
                                    tilingScheme:this._tilingScheme
                                });
                                var curWest=parentWest+col*deltaD;
                                var curEast=curWest+deltaD;
                                var curNorth=parentNorth-row*deltaD;
                                var curSouth=curNorth-deltaD;

                                childTile.centerSign=this.centerSign;//孩子和父亲一定相同

                                childTile.tileRect=DMSRectangle.constructWithOneComponent(this.tileRect,1,curWest,curSouth,curEast,curNorth);
                               // childTile.tileRect.changeSign(this.centerSign);
                                
                                if(this.bClamped){//父亲塌陷，则应考虑儿子
                                    childTile.realRect=childTile.tileRect.clampToRectNorthEast(this.tileRect,1);
                                    childTile.bClamped=Cesium.defined(childTile.realRect)?childTile.realRect.bClamped:true;
                                }
                                else{
                                    
                                    childTile.realRect=DMSRectangle.clone(childTile.tileRect);
                                    childTile.bClamped=false;
                                }
                                childTile.tileRect.changeSign(this.centerSign);
                                
                                
                                childTile._parent=this;
                            
                                if(Cesium.defined(childTile.realRect))
                                {
                                    childTile.realRect.changeSign(this.centerSign);
                                    result.push(childTile);
                                    
                                }
                                  
        
                            }
                        }
                        //变回原象限
                        this.tileRect.changeSign(this.centerSign);

                    }
                    else if(level>=15 && level<=20){
                        //变换为第一象限
                        if(!Cesium.defined(this.centerSign)){
                            this.centerSign=this.tileRect.sign();
                        }
                        this.tileRect.changeSign(this.centerSign);
                     
                        var gD=64;
                        if(level==15 && this.tileRect.east.second==0){
                            this.tileRect.east.minute-=1;
                            this.tileRect.north.minute-=1;
                            this.tileRect.east.second+=gD;
                            this.tileRect.north.second+=gD;

                            this.bClamped=true;
                        }

                        var parentWest=this.tileRect.west.second;
                        var parentNorth=this.tileRect.north.second;

                        var deltaD=gD/(2<<(level-15));
                        for(var row=0;row<2;row++){
                            for(var col=0;col<2;col++){
                                var childTile=new GlobeSpaceTile({
                                    x:2*x+col,
                                    y:2*y+row,
                                    level:level+1,
                                    tilingScheme:this._tilingScheme
                                });
                                var curWest=parentWest+col*deltaD;
                                var curEast=curWest+deltaD;
                                var curNorth=parentNorth-row*deltaD;
                                var curSouth=curNorth-deltaD;

                                childTile.centerSign=this.centerSign;//孩子和父亲一定相同

                                childTile.tileRect=DMSRectangle.constructWithOneComponent(this.tileRect,2,curWest,curSouth,curEast,curNorth);
                               // childTile.tileRect.changeSign(this.centerSign);
                                
                                if(this.bClamped){//父亲塌陷，则应考虑儿子
                                    childTile.realRect=childTile.tileRect.clampToRectNorthEast(this.tileRect,2);
                                    childTile.bClamped=Cesium.defined(childTile.realRect)?childTile.realRect.bClamped:true;
                                }
                                else{
                                    
                                    childTile.realRect=DMSRectangle.clone(childTile.tileRect);
                                    childTile.bClamped=false;
                                }
                                childTile.tileRect.changeSign(this.centerSign);
                                
                                
                                childTile._parent=this;
                            
                                if(Cesium.defined(childTile.realRect))
                                {
                                    childTile.realRect.changeSign(this.centerSign);
                                    result.push(childTile);
                                    
                                }
                                  
        
                            }
                        }
                        //变回原象限
                        this.tileRect.changeSign(this.centerSign);

                    }
                    else if(level>=21 && level<=31){
                        //变换为第一象限
                        if(!Cesium.defined(this.centerSign)){
                            this.centerSign=this.tileRect.sign();
                        }
                        this.tileRect.changeSign(this.centerSign);
                     
                        var gD=2048;
                        if(level==21 && this.tileRect.east.subSecond==0){
                            this.tileRect.east.second-=1;
                            this.tileRect.north.second-=1;
                            this.tileRect.east.subSecond+=gD;
                            this.tileRect.north.subSecond+=gD;

                            this.bClamped=false;
                        }

                        var parentWest=this.tileRect.west.subSecond;
                        var parentNorth=this.tileRect.north.subSecond;

                        var deltaD=gD/(2<<(level-21));
                        for(var row=0;row<2;row++){
                            for(var col=0;col<2;col++){
                                var childTile=new GlobeSpaceTile({
                                    x:2*x+col,
                                    y:2*y+row,
                                    level:level+1,
                                    tilingScheme:this._tilingScheme
                                });
                                var curWest=parentWest+col*deltaD;
                                var curEast=curWest+deltaD;
                                var curNorth=parentNorth-row*deltaD;
                                var curSouth=curNorth-deltaD;

                                childTile.centerSign=this.centerSign;//孩子和父亲一定相同

                                childTile.tileRect=DMSRectangle.constructWithOneComponent(this.tileRect,3,curWest,curSouth,curEast,curNorth);
                               // childTile.tileRect.changeSign(this.centerSign);
                                
                                if(this.bClamped){//父亲塌陷，则应考虑儿子
                                    childTile.realRect=childTile.tileRect.clampToRectNorthEast(this.tileRect,3);
                                    childTile.bClamped=Cesium.defined(childTile.realRect)?childTile.realRect.bClamped:true;
                                }
                                else{
                                    
                                    childTile.realRect=DMSRectangle.clone(childTile.tileRect);
                                    childTile.bClamped=false;
                                }
                                childTile.tileRect.changeSign(this.centerSign);
                                
                                
                                childTile._parent=this;
                            
                                if(Cesium.defined(childTile.realRect))
                                {
                                    childTile.realRect.changeSign(this.centerSign);
                                    result.push(childTile);
                                    
                                }
                                  
        
                            }
                        }
                        //变回原象限
                        this.tileRect.changeSign(this.centerSign);

                    }


                    this._children=result;
                   
                }
                return this._children;
            }
           
          
        },

      
        rectangle:{
            get:function(){
                if(!Cesium.defined(this._rectangle)){
                    var west=this.realRect.west.toDoubleDegree();
                    var south=this.realRect.south.toDoubleDegree();
                    var east=this.realRect.east.toDoubleDegree();
                    var north=this.realRect.north.toDoubleDegree();
                    this._rectangle=new Cesium.Rectangle(
                        Cesium.Math.toRadians(west),
                        Cesium.Math.toRadians(south),
                        Cesium.Math.toRadians(east),
                        Cesium.Math.toRadians(north)
                    );
                }
                return this._rectangle;
            }
        },
       tilingScheme:{
           get:function(){
               return this._tilingScheme;
           }
       },

        /**
         * An array of objects associated with this tile.
         * @memberof GlobeSpaceTile.prototype
         * @type {Array}
         */
        customData : {
            get : function() {
                return this._customData;
            }
        },

        /**
         * Gets a value indicating whether or not this tile needs further loading.
         * This property will return true if the {@link GlobeSpaceTile#state} is
         * <code>START</code> or <code>LOADING</code>.
         * @memberof GlobeSpaceTile.prototype
         * @type {Boolean}
         */
        needsLoading : {
            get : function() {
                return this.state < Cesium.QuadtreeTileLoadState.DONE;
            }
        },

        /**
         * Gets a value indicating whether or not this tile is eligible to be unloaded.
         * Typically, a tile is ineligible to be unloaded while an asynchronous operation,
         * such as a request for data, is in progress on it.  A tile will never be
         * unloaded while it is needed for rendering, regardless of the value of this
         * property.  If {@link GlobeSpaceTile#data} is Cesium.defined and has an
         * <code>eligibleForUnloading</code> property, the value of that property is returned.
         * Otherwise, this property returns true.
         * @memberof GlobeSpaceTile.prototype
         * @type {Boolean}
         */
        eligibleForUnloading : {
            get : function() {
                var result = true;

                if (Cesium.defined(this.data)) {
                    result = this.data.eligibleForUnloading;
                    if (!Cesium.defined(result)) {
                        result = true;
                    }
                }

                return result;
            }
        }
    });

 
    DMSValue.codeDmsValue=function(dmsValue){
        var degree=dmsValue.degree;
        var minute=dmsValue.minute;
        var second=dmsValue.second;
        var subSecond=dmsValue.subSecond;
        if(subSecond>=2048){
            subSecond-=2048;
            second+=1;
        }
        if(second>=60){
            second-=60;
            minute+=1;
        }
        if(minute>=60){
            minute-=60;
            degree+=1;
        }
        //subSecond/=2048.0;
        //subSecond=parseInt(subSecond*10000);
     
        var curDegree=Math.abs(parseInt(degree)).toString(2).slice(-8).padStart(8,'0');
        var curMinute=Math.abs(parseInt(minute)).toString(2).slice(-6).padStart(6,'0');
        var curSecond=Math.abs(parseInt(second)).toString(2).slice(-6).padStart(6,'0');
        var curSubSecond=Math.abs(parseInt(subSecond)).toString(2).slice(-11).padStart(11,'0');
        var result={};
        var dmsdouble=dmsValue.toDoubleDegree();
        result.sign=Math.sign(dmsdouble);
        result.value=(curDegree+curMinute+curSecond+curSubSecond).padStart(32,'0');
        return result;


    }
     DMSValue.motonCross=function(str1,str2,level){
        var result='';
        for(var i=0;i<str1.length;i++){
            result=result+str1.substring(i,i+1)+str2.substring(i,i+1);
        }
        var num=parseInt(result,2);
        num=num.toString(4);
        num=num.padStart(31,'0');//应该32位，缺少一位由调用函数象限符号确定
        num=num.substring(0,level-1);
        return num;
    }
   

    /**
     * Frees the resources associated with this tile and returns it to the <code>START</code>
     * {@link Cesium.QuadtreeTileLoadState}.  If the {@link GlobeSpaceTile#data} property is Cesium.defined and it
     * has a <code>freeResources</code> method, the method will be invoked.
     *
     * @memberof GlobeSpaceTile
     */
    GlobeSpaceTile.prototype.freeResources = function() {
        this.state = Cesium.QuadtreeTileLoadState.START;
        this.renderable = false;
        this.upsampledFromParent = false;

        if (Cesium.defined(this.data) && Cesium.defined(this.data.freeResources)) {
            this.data.freeResources();
        }
        if(Cesium.defined(this._children)){
            for(var i=0;i<this._children.length;i++){
                var tile=this._children[i];
                freeTile(tile);
            }
            this._children=undefined;
        }
      
    };

    

    function freeTile(tile) {
        if (Cesium.defined(tile)) {
            tile.freeResources();
           
        }
    }

    
     function DMSRectangle (options){
        if(!Cesium.defined(options)){
            this.west=new DMSValue();
            this.south=new DMSValue();
            this.east=new DMSValue();
            this.north=new DMSValue();
            return;
        }
        this.west=Cesium.defaultValue(options.west,new DMSValue());
        this.south=Cesium.defaultValue(options.south,new DMSValue());
        this.east=Cesium.defaultValue(options.east,new DMSValue());
        this.north=Cesium.defaultValue(options.north,new DMSValue());
    }
    DMSRectangle.prototype.sign=function(){
        var result={};
        result.x=Math.sign((this.west.degree+this.east.degree)/2) ; 
        result.y=Math.sign((this.south.degree+this.north.degree)/2);
        return result;  
    }
    DMSRectangle.prototype.changeSign=function(sign){
        this.west.changeSign(sign.x);
        this.south.changeSign(sign.y);
        this.east.changeSign(sign.x);
        this.north.changeSign(sign.y);

        if(sign.x<0){
            var temp=this.west;
            this.west=this.east;
            this.east=temp;
        }
        if(sign.y<0){
            var temp=this.south;
            this.south=this.north;
            this.north=temp;
        }
    }
    Object.defineProperties(DMSRectangle.prototype,{
      
        
    });
    DMSRectangle.clone=function(dmsRect){
       var result=new DMSRectangle({
           west:DMSValue.clone(dmsRect.west),
           south:DMSValue.clone(dmsRect.south),
           east:DMSValue.clone(dmsRect.east),
           north:DMSValue.clone(dmsRect.north)
       });
       return result;
    }
    DMSRectangle.constructWithDegree=function(westDegree,southDegree,eastDegree,northDegree){
        return new DMSRectangle({
            west:new DMSValue({
                degree:westDegree
            }),
            south:new DMSValue({
                degree:southDegree
            }),
            east:new DMSValue({
                degree:eastDegree
            }),
            north:new DMSValue({
                degree:northDegree
            })
        });
    }
    DMSRectangle.constructWithOneComponent=function(initRect,componentType,westCom,southCom,eastCom,northCom){
       var result=DMSRectangle.clone(initRect);
       switch(componentType){
           case 0:
               result.west.degree=westCom;
               result.south.degree=southCom;
               result.east.degree=eastCom;
               result.north.degree=northCom;
               break;
            case 1:
                result.west.minute=westCom;
                result.south.minute=southCom;
                result.east.minute=eastCom;
                result.north.minute=northCom;
                break; 
            case 2:
                result.west.second=westCom;
                result.south.second=southCom;
                result.east.second=eastCom;
                result.north.second=northCom;
                break;
            case 3:
                result.west.subSecond=westCom;
                result.south.subSecond=southCom;
                result.east.subSecond=eastCom;
                result.north.subSecond=northCom;
                break;     
       }
       return result;

    }

    // DMSRectangle.constructWithMinute=function(oriRect,westMinute,southMinute,eastMinute,northMinute){
    //     return new DMSRectangle({
    //         west:new DMSValue({
    //             degree:oriRect.west.degree,
    //             minute:westMinute
    //         }),
    //         south:new DMSValue({
    //             degree:oriRect.south.degree,
    //             minute:southMinute
    //         }),
    //         east:new DMSValue({
    //             degree:oriRect.east.degree,
    //             minute:eastMinute
    //         }),
    //         north:new DMSValue({
    //             degree:oriRect.north.degree,
    //             minute:northMinute
    //         })
    //     });
    // }

    DMSRectangle.prototype.clampToEarth=function(){
        if(this.east.degree<earthDmsRectangle.west.degree || this.north.degree<earthDmsRectangle.south.degree
        || this.west.degree>earthDmsRectangle.east.degree || this.south.degree>earthDmsRectangle.north.degree)
        return undefined;
        var westDegree=this.west.degree<earthDmsRectangle.west.degree?earthDmsRectangle.west.degree:this.west.degree;
        var southDegree=this.south.degree<earthDmsRectangle.south.degree?earthDmsRectangle.south.degree:this.south.degree;
        var eastDegree=this.east.degree>earthDmsRectangle.east.degree?earthDmsRectangle.east.degree:this.east.degree;
        var northDegree=this.north.degree>earthDmsRectangle.north.degree?earthDmsRectangle.north.degree:this.north.degree;
        return DMSRectangle.constructWithDegree(westDegree,southDegree,eastDegree,northDegree);
    }
    // DMSRectangle.prototype.clampToMinute=function(oriRect){
    //     if(this.east.minute<minuteDmsRectangle.west.minute || this.north.minute<minuteDmsRectangle.south.minute
    //     || this.west.minute>minuteDmsRectangle.east.minute || this.south.minute>minuteDmsRectangle.north.minute)
    //     return undefined;
    //     var westDegree=this.west.minute<minuteDmsRectangle.west.minute?minuteDmsRectangle.west.minute:this.west.minute;
    //     var southDegree=this.south.minute<minuteDmsRectangle.south.minute?minuteDmsRectangle.south.minute:this.south.minute;
    //     var eastDegree=this.east.minute>minuteDmsRectangle.east.minute?minuteDmsRectangle.east.minute:this.east.minute;
    //     var northDegree=this.north.minute>minuteDmsRectangle.north.minute?minuteDmsRectangle.north.minute:this.north.minute;
    //     return DMSRectangle.constructWithMinute(oriRect,westDegree,southDegree,eastDegree,northDegree);
    // }
    DMSRectangle.prototype.clampToRectNorthEast=function(oriRect,componentType){
        var westCom,southCom,eastCom,northCom;
        var bClamped=false;
        if(componentType==0){
            if( this.west.degree>=earthDmsRectangle.east.degree || this.south.degree>=earthDmsRectangle.north.degree)
            return undefined;
            southCom=this.south.degree;
            westCom=this.west.degree;
            
            if(this.east.degree>earthDmsRectangle.east.degree){
                eastCom=earthDmsRectangle.east.degree
                bClamped=true;
            }
            else{
                eastCom=this.east.degree
            }

            if(this.north.degree>earthDmsRectangle.north.degree){
                northCom=earthDmsRectangle.north.degree
                bClamped=true;
            }
            else{
                northCom=this.north.degree
            }
            var result= DMSRectangle.constructWithOneComponent(oriRect,componentType,westCom,southCom,eastCom,northCom);
            result.bClamped=bClamped;
            return result;
        }
        if(componentType==1){
            if( this.west.minute>=earthDmsRectangle.east.minute || this.south.minute>=earthDmsRectangle.north.minute)
            return undefined;
            southCom=this.south.minute;
            westCom=this.west.minute;
            
            if(this.east.minute>earthDmsRectangle.east.minute){
                eastCom=earthDmsRectangle.east.minute
                bClamped=true;
            }
            else{
                eastCom=this.east.minute
            }

            if(this.north.minute>earthDmsRectangle.north.minute){
                northCom=earthDmsRectangle.north.minute
                bClamped=true;
            }
            else{
                northCom=this.north.minute
            }
            var result= DMSRectangle.constructWithOneComponent(oriRect,componentType,westCom,southCom,eastCom,northCom);
            result.bClamped=bClamped;
            return result;
        }
        if(componentType==2){
            if( this.west.second>=earthDmsRectangle.east.second || this.south.second>=earthDmsRectangle.north.second)
            return undefined;
            southCom=this.south.second;
            westCom=this.west.second;
            
            if(this.east.second>earthDmsRectangle.east.second){
                eastCom=earthDmsRectangle.east.second
                bClamped=true;
            }
            else{
                eastCom=this.east.second
            }

            if(this.north.second>earthDmsRectangle.north.second){
                northCom=earthDmsRectangle.north.second
                bClamped=true;
            }
            else{
                northCom=this.north.second
            }
            var result= DMSRectangle.constructWithOneComponent(oriRect,componentType,westCom,southCom,eastCom,northCom);
            result.bClamped=bClamped;
            return result;
        }
        return undefined;

      
    }


     function DMSValue(options){
        if(!Cesium.defined(options)){
            this.degree=0
            this.minute=0;
            this.second=0;
            this.subSecond=0;//2048 per second
            return;
        }
        this.degree=Cesium.defaultValue(options.degree,0);
        this.minute=Cesium.defaultValue(options.minute,0);
        this.second=Cesium.defaultValue(options.second,0);
        this.subSecond=Cesium.defaultValue(options.subSecond,0);//2048 per second
    }
    DMSValue.Add=function(d1,d2){
        return new DMSValue({
            degree:d1.degree+d2.degree,
            minute:d1.minute+d2.minute,
            second:d1.second+d2.second,
            subSecond:d1.subSecond+d2.subSecond
        })
    }
    DMSValue.divide=function(d1,num){
        return new DMSValue({
            degree:d1.degree/num,
            minute:d1.minute/num,
            second:d1.second/num,
            subSecond:d1.subSecond/num
        })
    }
    DMSValue.clone=function(dmsValue){
        
        var result=new DMSValue();
       
        result.degree=dmsValue.degree;
        result.minute=dmsValue.minute;
        result.second=dmsValue.second;
        result.subSecond=dmsValue.subSecond;
        return result;
    }
    DMSValue.prototype.toDoubleDegree=function(){
        return this.degree+this.minute/60+this.second/3600+this.subSecond/7372800;
    }
    DMSValue.prototype.changeSign=function(sign){
        this.degree*=sign;
        this.minute*=sign;
        this.second*=sign;
        this.subSecond*=sign;
    }

    var zeroRectangle=new DMSRectangle();
    var earthDmsRectangle= DMSRectangle.constructWithOneComponent(zeroRectangle,0,-180,-88,180,88);//地球空间
     earthDmsRectangle=DMSRectangle.constructWithOneComponent(earthDmsRectangle,1,0,0,60,60);//分和秒的空间
     earthDmsRectangle=DMSRectangle.constructWithOneComponent(earthDmsRectangle,2,0,0,60,60);//分和秒的空间
// export default GlobeSpaceTile;
